package com.atguigu.l_collect;

import java.util.Date;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo2 {
    public static void main(String[] args) {
        //进工厂
        Stream<String> stream = Stream.of("1000", "2000", "3000");

        //中间操作 -> 省略
        //出工厂  Map<Integer,Date> --> {1=时间1,2=时间2,3=时间3}
        //Map<Object, Object> map = stream.collect(Collectors.toMap(如果把T转成K, 如何把T转成V));
        //自己改写 Lambda
        Map<Integer, Date> map = stream.collect(Collectors.toMap(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s) / 1000;
            }
        }, new Function<String, Date>() {
            @Override
            public Date apply(String s) {
                return new Date(Integer.parseInt(s));
            }
        }));

        System.out.println("map = " + map);
    }
}
